<?php
if(stristr($_SERVER['REQUEST_URI'], 'maketoken.php')) die('system halted');
function makeToken() {
	$num = floor(($_SERVER['REQUEST_TIME_FLOAT'] - 1480600000) * 10000) . rand(100, 999);
    $t = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $str = '';
    while($num>0) {
        $n = $num % 62;
        $num = floor($num / 62);
        $str = substr($t, $n, 1) . $str;
    }
    return $str;
}
if (is_null($_COOKIE['user_token'])) {
	$token = makeToken();
} else {
	$token = $_COOKIE['user_token'];
}
$sql = "INSERT INTO user_track (user_token, user_ip, current_uri, spend_time, from_where, user_browser, visit_time) VALUES ('$token', '"
	.$_SERVER['REMOTE_ADDR']."', '".$_SERVER['REQUEST_URI']."', '65499', '".$_SERVER['HTTP_REFERER']."', '"
	.$_SERVER['HTTP_USER_AGENT']."', '".time()."');";
$dbh->exec($sql);
$n = $dbh->lastInsertId();
setcookie('user_token', $token, time() + 86400 * 30);
setcookie('user_token_time', substr($_SERVER['REQUEST_TIME_FLOAT'], 8), time() + 3600);
setcookie('user_token_id', str_pad($n, 9, '0', STR_PAD_LEFT), time() + 3600);
